#include <stdio.h>
#include <pthread.h>
#include <unistd.h>

void *thread_func(void *arg){
    printf("thread_func start\n");

    printf("thread_func is working\n");
    sleep(3);

    printf("thread_func end\n");

    return NULL;
}

int main(int argc, char const *argv[])
{
    printf("main start\n");

    pthread_t tid;
    pthread_create(&tid, NULL, thread_func, NULL);

    sleep(1);

    // 取消线程
    pthread_cancel(tid);

    // 等待线程结束
    void *result;
    pthread_join(tid, &result);
    if (result == PTHREAD_CANCELED)
    {
        printf("thread is canceled\n");
    }else{
        printf("thread is not canceled\n");
    }

    printf("main end\n");

    return 0;
}
